﻿
var actionURL = "../sicpet/GetYBQ.ashx";
var uid;
var cid = "";
var dtOpstart;
var dtOpend;
var filterObj;
var ch = new Array("", "", "", "");
var XQHID = "";
var chs = "";
var tc1 = "";
var tc2 = "";
var tc3 = "";
var tc4 = "";
Array.prototype.deleteElementByValue = function (varElement) {
    var numDeleteIndex = -1;
    for (var i = 0; i < this.length; i++) {
        // 严格比较，即类型与数值必须同时相等。
        if (this[i] === varElement) {
            this.splice(i, 1);
            numDeleteIndex = i;
            break;
        }
    }
    return numDeleteIndex;
}
function getUrlParam(name) {
    var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)"); //构造一个含有目标参数的正则表达式对象
    var r = window.location.search.substr(1).match(reg);  //匹配目标参数
    if (r != null) return unescape(r[2]); return null; //返回参数值
}
var mylayout = {
    init: function (size) {
        $('#layout').width(size.width - 4).height(size.height - 4).layout();
        var center = $('#layout').layout('panel', 'center');
        //grid.bind(size);
        center.panel({
            onResize: function (w, h) {
                $('#histList').datagrid('resize', { width: w, height: h });
            }
        });
    },
    resize: function (size) {
        mylayout.init(size);
        $('#layout').layout('resize');
    }
};


function ConvertJSONDateToJSDate(jsondate) {
    var date = new Date(parseInt(jsondate, 10));
    return date;
}
var chartInstance;
var ChartJS = {
    init: function (ch1, ch2, ch3, ch4) {
        var s = "[";
        if (ch1 != "")
            s = s + "{name:'" + ch1 + "',data:[]},";
        if (ch2 != "")
            s = s + "{name:'" + ch2 + "',data:[]},";
        if (ch3 != "")
            s = s + "{name:'" + ch3 + "',data:[]},";
        if (ch4 != "")
            s = s + "{name:'" + ch4 + "',data:[]}";
        if (s.substring(s.length - 1, s.length) == ",")
            s = s.substr(0, s.length - 1);
        s = s + "]";
        chartInstance = new Highcharts.Chart({
            chart: {
                renderTo: 'chartArea',
                type: 'line'
            },
            credits: {
                enabled: false
            },
            exporting: {
                enabled: true
            },
            title: {
                text: '靶标害虫历史曲线 - 请点击害虫记录选择具体通道',
                x: -20 //center
            },
            xAxis: {
                type: 'datetime',
                labels: {
                    //step: 4,
                    formatter: function () {
                        return new Date(this.value).toLocaleDateString();
                    }
                }
            },
            yAxis: {
                title: {
                    text: '数量 (只)'
                },
                plotLines: [{
                    value: 0,
                    width: 1,
                    color: '#808080'
                }]
            },
            tooltip: {
                valueSuffix: '只',
                formatter: function () {
                    return '<b>' + this.series.name + '：</b>' + this.y + '只<br/> <b>时间：</b>' + new Date(this.x).toLocaleString();
                    //return '<b>' + this.series.name + '：</b>' + this.y + '只<br/> <b>时间：</b>' + this.x;
                }

            },
            legend: {
                layout: 'vertical',
                align: 'right',
                verticalAlign: 'middle',
                borderWidth: 0
            },
            series: eval(s)
        });
    }
};

var wchartInstance;
var WChartJS = {
    init: function (chs, ch1, ch2, ch3, ch4) {
        var s = "[";
        $.each(chs, function () {
            s = s + "{name:'" + this + "',yAxis: 1,data:[]},";
        });
        if (ch1 != "")
            s = s + "{name:'" + ch1 + "',data:[]},";
        if (ch2 != "")
            s = s + "{name:'" + ch2 + "',data:[]},";
        if (ch3 != "")
            s = s + "{name:'" + ch3 + "',data:[]},";
        if (ch4 != "")
            s = s + "{name:'" + ch4 + "',data:[]}";
        if (s.substring(s.length - 1, s.length) == ",")
            s = s.substr(0, s.length - 1);
        s = s + "]";
        wchartInstance = new Highcharts.Chart({
            chart: {
                renderTo: 'chartArea',
                type: 'line'
            },
            credits: {
                enabled: false
            },
            exporting: {
                enabled: true
            },
            title: {
                text: '小气候数据',
                x: -20 //center
            },
            plotOptions: {
                series: {
                    events: {
                        legendItemClick: function () {
                            var visibility = this.visible ? 'visible' : 'hidden';
                            if (visibility == 'hidden') {
                                for (var i = 0; i < chs.length; i++) {
                                    wchartInstance.series[i].hide();

                                }
                                //wchartInstance.series
                            }
                            return true;
                        }
                    }
                }
            },
            xAxis: {
                type: 'datetime',
                labels: {
                    step: 4,
                    formatter: function () {
                        return new Date(this.value).toLocaleDateString();
                    }
                }
            },
            yAxis: [{
                title: {
                    text: '虫子数值'
                },
                plotLines: [{
                    value: 0,
                    width: 1,
                    color: '#808080'
                }]
            },
            {
                title: {
                    text: '气象数值'
                },
                plotLines: [{
                    value: 0,
                    width: 1,
                    color: '#89A54E'
                }],
                opposite: true
            }],
            tooltip: {
                //valueSuffix: '',
                formatter: function () {
                    var sname = this.series.name;
                    if (sname.substr(sname.length - 1, 1) == '度')
                        return '<b>' + sname + '：</b>' + this.y + '℃<br/> <b>时间：</b>' + new Date(this.x).toLocaleString();
                    else
                        return '<b>' + sname + '：</b>' + this.y + '<br/> <b>时间：</b>' + new Date(this.x).toLocaleString();
                }

            },
            legend: {
                layout: 'vertical',
                align: 'right',
                verticalAlign: 'middle',
                borderWidth: 0
            },
            series: eval(s)
        });
        for (var i = 0; i < chs.length; i++) {
            wchartInstance.series[i].hide();

        }
        wchartInstance.series[0].show();
    }
};
function winit(chs, ch1, ch2, ch3, ch4) {
    var s = "[";
    $.each(chs, function () {
        s = s + "{name:'" + this + "',yAxis: 1,data:[]},";
    });
    if (ch1 != "")
        s = s + "{name:'" + ch1 + "',data:[]},";
    if (ch2 != "")
        s = s + "{name:'" + ch2 + "',data:[]},";
    if (ch3 != "")
        s = s + "{name:'" + ch3 + "',data:[]},";
    if (ch4 != "")
        s = s + "{name:'" + ch4 + "',data:[]}";
    if (s.substring(s.length - 1, s.length) == ",")
        s = s.substr(0, s.length - 1);
    s = s + "]";
    wchartInstance = new Highcharts.Chart({
        chart: {
            renderTo: 'chartArea',
            type: 'line'
        },
        credits: {
            enabled: false
        },
        exporting: {
            enabled: true
        },
        title: {
            text: '小气候数据',
            x: -20 //center
        },
        plotOptions: {
            series: {
                events: {
                    legendItemClick: function () {
                        var visibility = this.visible ? 'visible' : 'hidden';
                        if (visibility == 'hidden') {
                            for (var i = 0; i < chs.length; i++) {
                                wchartInstance.series[i].hide();

                            }
                            //wchartInstance.series
                        }
                        return true;
                    }
                }
            }
        },
        xAxis: {
            type: 'datetime',
            labels: {
                step: 4,
                formatter: function () {
                    return new Date(this.value).toLocaleDateString();
                }
            }
        },
        yAxis: [{
            title: {
                text: '虫子数值'
            },
            plotLines: [{
                value: 0,
                width: 1,
                color: '#808080'
            }]
        },
        {
            title: {
                text: '气象数值'
            },
            plotLines: [{
                value: 0,
                width: 1,
                color: '#89A54E'
            }],
            opposite: true
        }],
        tooltip: {
            //valueSuffix: '',
            formatter: function () {
                var sname = this.series.name;
                if (sname.substr(sname.length - 1, 1) == '度')
                    return '<b>' + sname + '：</b>' + this.y + '℃<br/> <b>时间：</b>' + new Date(this.x).toLocaleString();
                else
                    return '<b>' + sname + '：</b>' + this.y + '<br/> <b>时间：</b>' + new Date(this.x).toLocaleString();
            }

        },
        legend: {
            layout: 'vertical',
            align: 'right',
            verticalAlign: 'middle',
            borderWidth: 0
        },
        series: eval(s)
    });
    for (var i = 0; i < chs.length; i++) {
        wchartInstance.series[i].hide();

    }
    wchartInstance.series[0].show();
}
function contains(string, substr, isIgnoreCase) {
    if (isIgnoreCase) {
        string = string.toLowerCase();
        substr = substr.toLowerCase();
    }
    var startChar = substr.substring(0, 1);
    var strLen = substr.length;
    for (var j = 0; j < string.length - strLen + 1; j++) {
        if (string.charAt(j) == startChar) //如果匹配起始字符,开始查找
        {
            if (string.substring(j, j + strLen) == substr) //如果从j开始的字符与str匹配，那ok
            {
                return true;
            }
        }
    }
    return false;
}
function Minit(){
    cid =devid;
    var note = '美国白蛾,,,';
    ch = note.split(',');
    XQHID = '1064821314477';
    if (XQHID != "" && XQHID != null)
        jQuery.getJSON(qxurl + '/Dev/ashx/DevCon.ashx?action=getmylist&XQHID=' + XQHID + '&r=' + Math.floor(Math.random() * (1000 + 1)), null, function (data) {

            chs = data.XQHID.split(',');
            chs.deleteElementByValue("风向");
            if (chs.length != 0)
                winit(chs, ch[0], ch[1], ch[2], ch[3]);
        });
    else
        winit(chs, ch[0], ch[1], ch[2], ch[3]);
    var ruleArr = [];
    dtOpstart = $('#dtOpstart').datebox('getValue');
    dtOpend = $('#dtOpend').datebox('getValue');
    if (cid != "") {
        ruleArr.push({ "field": "devID", "op": "eq", "data": cid });
    }
    if (dtOpstart != '')
        ruleArr.push({ "field": "updateTime", "op": "ge", "data": dtOpstart });
    if (dtOpend != '')
        ruleArr.push({ "field": "updateTime", "op": "le", "data": dtOpend });
    if (ruleArr.length > 0) {
        filterObj = { groupOp: 'AND', rules: ruleArr };
        $('body').data('where', JSON.stringify(filterObj));
    }
    var cols = "[[{ title: '设备ID', field: 'devID', width: 100, align: 'center' },"
    if (ch[0] != "")
        cols = cols + "{ title:'" + ch[0] + "', field: 'ch0', width: 80, align: 'center' },";
    if (ch[1] != "")
        cols = cols + "{ title:'" + ch[1] + "', field: 'ch1', width: 80, align: 'center' },";
    if (ch[2] != "")
        cols = cols + "{ title:'" + ch[2] + "', field: 'ch2', width: 80, align: 'center' },";
    if (ch[3] != "")
        cols = cols + "{ title:'" + ch[3] + "', field: 'ch3', width: 80, align: 'center' },";
    cols = cols + "{ title: '更新时间', field: 'updateTime', width: 150, align: 'center' },{ title: '备注', field: 'Note', width: 120, align: 'center' }]]";
    $('#histList').datagrid({
        title: "设备的历史记录",
        url: actionURL + '?Action=detail',
        queryParams: { devID: devid },
        pagination: true,
        pageSize: 1000,
        pageList: [10, 20, 40, 1000, 10000],
        columns: eval(cols),
        onLoadSuccess: function (data) {

            var mt = "";
            var md;
            tc1 = "";
            tc2 = "";
            tc3 = "";
            tc4 = "";
            $.each(data.rows, function (k, v) {
                mt = v["updateTime"];
                mt = mt.replace(/-/g, "/");
                md = Date.parse(mt);
                tc1 += "[" + md + "," + v["ch0"] + "],";
                tc2 += "[" + md + "," + v["ch1"] + "],";
                tc3 += "[" + md + "," + v["ch2"] + "],";
                tc4 += "[" + md + "," + v["ch3"] + "],";
            });
            tc1 = "[" + tc1 + "]";
            tc2 = "[" + tc2 + "]";
            tc3 = "[" + tc3 + "]";
            tc4 = "[" + tc4 + "]";
            var n = chs.length;

            var num = 0;
            if (ch[0] != "") {
                wchartInstance.series[n + num].setData(eval(tc1));
                num = num + 1;
            }
            if (ch[1] != "") {
                wchartInstance.series[n + num].setData(eval(tc2));
                num = num + 1;
            }
            if (ch[2] != "") {
                wchartInstance.series[n + num].setData(eval(tc3));
                num = num + 1;
            }
            if (ch[3] != "") {
                wchartInstance.series[n + num].setData(eval(tc4));
                num = num + 1;
            }
            //分析结果
            griddata = data;
            var max = 0;
            var min = 0;
            var sum = 0;
            var pets = "";
            var temp = 0;
            var nums = 0;
            var maxt = "";
            var mint = "";
            var sresult = "";
            var snum = 0;
            var result = "";
            dtOpstart = $('#dtOpstart').datebox('getValue');
            dtOpend = $('#dtOpend').datebox('getValue');
            num = 0;
            if (ch[0] != "") {

                num = num + 1;
                pets = pets + ch[0];
                max = 0;
                sum = 0;
                maxt = "";
                mint = "";
                snum = 0;
                sresult = "";
                $.each(data.rows, function (k, v) {
                    temp = parseInt(v["ch0"]);
                    if (temp >= max) { max = temp; maxt = v["updateTime"]; }
                    sum = sum + temp;
                });
                result = result + "其中" + ch[0] + "，最大数为：" + max + ",发生日期是：" + maxt + "。";
            }
            if (ch[1] != "") {
                pets = pets + ch[1];
                num = num + 1;
                max = 0;
                sum = 0;
                maxt = "";
                mint = "";
                snum = 0;
                sresult = "";
                $.each(data.rows, function (k, v) {
                    temp = parseInt(v["ch1"]);
                    if (temp >= max) { max = temp; maxt = v["updateTime"]; }
                    sum = sum + temp;
                });
                result = result + "其中" + ch[1] + "，最大数为：" + max + ",发生日期是：" + maxt + "。";
            }
            if (ch[2] != "") {
                pets = pets + ch[2];
                num = num + 1;
                max = 0;
                sum = 0;
                maxt = "";
                mint = "";
                snum = 0;
                sresult = "";
                $.each(data.rows, function (k, v) {
                    temp = parseInt(v["ch2"]);
                    if (temp >= max) { max = temp; maxt = v["updateTime"]; }
                    sum = sum + temp;
                });
                result = result + "其中" + ch[2] + "，最大数为：" + max + ",发生日期是：" + maxt + "。";
            }
            if (ch[3] != "") {
                pets = pets + ch[3];
                num = num + 1;
                max = 0;
                sum = 0;
                maxt = "";
                mint = "";
                snum = 0;
                sresult = "";
                $.each(data.rows, function (k, v) {
                    temp = parseInt(v["ch3"]);
                    if (temp >= max) { max = temp; maxt = v["updateTime"]; }
                    sum = sum + temp;
                });
                result = result + "其中" + ch[3] + "，最大数为：" + max + ",发生日期是：" + maxt + "。";
            }
            if (dtOpstart != "") dtOpstart = dtOpstart + "到";
            if (dtOpend != "") dtOpstart = dtOpstart + dtOpend;
            result = dtOpstart + "，" + uid + "靶标害虫中害虫" + num + "种，分别为：" + pets + "。" + result;
            //$('#yjfx').text(result);
        }
    });
}
function phoneavg() {
    dtOpstart = $('#dtOpstart').datebox('getValue');
    dtOpend = $('#dtOpend').datebox('getValue');
    var ruleArr = [];
    if (cid != "") {
        ruleArr.push({ "field": "devID", "op": "eq", "data": cid });
    }
    if (dtOpstart != '')
        ruleArr.push({ "field": "updateTime", "op": "ge", "data": dtOpstart });
    if (dtOpend != '')
        ruleArr.push({ "field": "updateTime", "op": "le", "data": dtOpend });
    if (ruleArr.length > 0) {
        filterObj = { groupOp: 'AND', rules: ruleArr };
        $('body').data('where', JSON.stringify(filterObj));
        $('#histList').datagrid({
            queryParams: { filter: JSON.stringify(filterObj), devID: cid },
            url: actionURL + '?Action=avgday'
        });
    } else {
        $('#histList').datagrid({
            queryParams: { devID: cid },
            url: actionURL + '?Action=avgday'
        });
    }
}
function phoneavgm() {
    dtOpstart = $('#dtOpstart').datebox('getValue');
    dtOpend = $('#dtOpend').datebox('getValue');
    var ruleArr = [];
    if (cid != "") {
        ruleArr.push({ "field": "devID", "op": "eq", "data": cid });
    }
    if (dtOpstart != '')
        ruleArr.push({ "field": "updateTime", "op": "ge", "data": dtOpstart });
    if (dtOpend != '')
        ruleArr.push({ "field": "updateTime", "op": "le", "data": dtOpend });
    if (ruleArr.length > 0) {
        filterObj = { groupOp: 'AND', rules: ruleArr };
        $('body').data('where', JSON.stringify(filterObj));
        $('#histList').datagrid({
            queryParams: { filter: JSON.stringify(filterObj), devID: cid },
            url: actionURL + '?Action=avgmonth'
        });
    } else {
        $('#histList').datagrid({
            queryParams: { devID: cid },
            url: actionURL + '?Action=avgmonth'
        });
    }


}
function phoneavgx() {
    dtOpstart = $('#dtOpstart').datebox('getValue');
    dtOpend = $('#dtOpend').datebox('getValue');
    var ruleArr = [];
    if (cid != "") {
        ruleArr.push({ "field": "devID", "op": "eq", "data": cid });
    }
    if (dtOpstart != '')
        ruleArr.push({ "field": "updateTime", "op": "ge", "data": dtOpstart });
    if (dtOpend != '')
        ruleArr.push({ "field": "updateTime", "op": "le", "data": dtOpend });
    if (ruleArr.length > 0) {
        filterObj = { groupOp: 'AND', rules: ruleArr };
        $('body').data('where', JSON.stringify(filterObj));
        $('#histList').datagrid({
            queryParams: { filter: JSON.stringify(filterObj), devID: cid },
            url: actionURL + '?Action=avgxun'
        });
    } else {
        $('#histList').datagrid({
            queryParams: { devID: cid },
            url: actionURL + '?Action=avgxun'
        });
    }
}
var grid = {
    bind: function (winSize) {
        var cols = "[[{ title: '设备ID', field: 'devID', width: 100, align: 'center' },"
        if (ch[0] != "")
            cols = cols + "{ title:'" + ch[0] + "', field: 'ch0', width: 80, align: 'center' },";
        if (ch[1] != "")
            cols = cols + "{ title:'" + ch[1] + "', field: 'ch1', width: 80, align: 'center' },";
        if (ch[2] != "")
            cols = cols + "{ title:'" + ch[2] + "', field: 'ch2', width: 80, align: 'center' },";
        if (ch[3] != "")
            cols = cols + "{ title:'" + ch[3] + "', field: 'ch3', width: 80, align: 'center' },";
        cols = cols + "{ title: '更新时间', field: 'updateTime', width: 150, align: 'center' },{ title: '备注', field: 'Note', width: 120, align: 'center' }]]";

        $('#histList').datagrid({
            toolbar: '#toolbarm',
            //url: '/status_ybq/ashx/YBQHandler.ashx?Action=detail',
            title: "靶标害虫设备历史数据列表",
            iconCls: 'icon icon-list',
            width: winSize.width,
            height: winSize.height - 240,
            nowrap: true, //折行
            rownumbers: true, //行号
            striped: true, //隔行变色
            idField: 'keyid', //主键
            singleSelect: true, //单选
            fitColumns: true,
            //queryParams: { devID: cid },
            columns: eval(cols),
            pagination: true,
            pageSize: 10,
            pageList: [10, 20, 40, 50]
        });
    },
    getSelectedRow: function () {
        return $('#histList').datagrid('getSelected');
    },
    reload: function () {
        $('#histList').datagrid('clearSelections').datagrid('reload', { devID: cid });
    }
};

function createParam(action, keyid) {
    var o = {};
    var query = top.$('#uiform').serializeArray();
    query = convertArray(query);
    o.jsonEntity = JSON.stringify(query);
    o.action = action;
    o.keyid = keyid;
    return "json=" + JSON.stringify(o);
}
var CRUD = {
    init: function () {
        filterObj = "";
        dtOpstart = $('#dtOpstart').datebox('getValue');
        dtOpend = $('#dtOpend').datebox('getValue');
        var ruleArr = [];
        if (dtOpstart != '')
            ruleArr.push({ "field": "updateTime", "op": "ge", "data": dtOpstart });
        if (dtOpend != '')
            ruleArr.push({ "field": "updateTime", "op": "le", "data": dtOpend });
        if (ruleArr.length > 0) {
            filterObj = { groupOp: 'AND', rules: ruleArr };
            $('body').data('where', filterObj);
        }


    },
    showavg: function () {
        if (XQHID == "") {
            $.messager.alert("提示", "对不起，这个设备没有小气候数据！", "info");
            return;
        }
        CRUD.init();
        var rows = $('#histList').datagrid('getPager').data("pagination").options.pageSize;
        jQuery.getJSON(qxurl + '/status_xqh/ashx/XQH.ashx?action=phoneavg&devID=' + XQHID + '&filter=' + JSON.stringify(filterObj) + '&page=1&rows=' + rows + '&r=' + Math.floor(Math.random() * (1000 + 1)), null, function (data) {
            //$('#histList').datagrid('loadData',data);      
            var md;
            var t1 = "";
            var n = chs.length;
            for (var i = 0; i < n; i++) {
                t1 = "";
                $.each(data.rows, function (k, v) {
                    md = v["datetime"];
                    md = md.replace(/-/g, "/");
                    md = Date.parse(md);
                    t1 = "[" + md + "," + v[chs[i]] + "]," + t1;

                });
                t1 = "[" + t1 + "]";
                wchartInstance.series[i].setData(eval(t1));
            }
        });


    },
    showmavg: function () {
        if (XQHID == "") {
            $.messager.alert("提示", "对不起，这个设备没有小气候数据！", "info");
            return;
        }
        CRUD.init();
        var rows = $('#histList').datagrid('getPager').data("pagination").options.pageSize;
        jQuery.getJSON(qxurl + '/status_xqh/ashx/XQH.ashx?action=mavg&devID=' + XQHID + '&filter=' + JSON.stringify(filterObj) + '&page=1&rows=' + rows + '&r=' + Math.floor(Math.random() * (1000 + 1)), null, function (data) {
            //$('#histList').datagrid('loadData',data);    
            var md;
            var t1 = "";
            var n = chs.length;
            for (var i = 0; i < n; i++) {
                t1 = "";
                $.each(data.rows, function (k, v) {
                    md = v["datetime"] + "-01";
                    md = md.replace(/-/g, "/");
                    md = Date.parse(md);
                    t1 = "[" + md + "," + v[chs[i]] + "]," + t1;

                });
                t1 = "[" + t1 + "]";
                wchartInstance.series[i].setData(eval(t1));
            }
        });


    },
    show: function () {
        if (XQHID == "") {
            $.messager.alert("提示", "对不起，这个设备没有小气候数据！", "info");
            return;
        }
        CRUD.init();
        if (chs.length == 0) {
            $.messager.alert("提示", "对不起，这个设备小气候参数为空！", "info");

            return;
        }
        if (chs.length != 0)
            WChartJS.init(chs, ch[0], ch[1], ch[2], ch[3]);
        else
            $.messager.alert("提示", "对不起，这个设备小气候参数为空！", "info");

        var rows = $('#histList').datagrid('getPager').data("pagination").options.pageSize;
        jQuery.getJSON(qxurl + '/status_xqh/ashx/XQH.ashx?action=phone&devID=' + XQHID + '&filter=' + JSON.stringify(filterObj) + '&page=1&rows=' + rows + '&r=' + Math.floor(Math.random() * (1000 + 1)), null, function (data) {

            var md;
            var t1 = "";
            var n = chs.length;
            for (var i = 0; i < n; i++) {
                t1 = "";
                $.each(data.rows, function (k, v) {
                    md = v["datetime"];
                    md = md.replace(/-/g, "/");
                    md = Date.parse(md);
                    t1 = "[" + md + "," + v[chs[i]] + "]," + t1;
                });
                t1 = "[" + t1 + "]";
                wchartInstance.series[i].setData(eval(t1));
            }
            var num = 0;
            if (ch[0] != "") {
                wchartInstance.series[n + num].setData(eval(tc1));
                num = num + 1;
            }
            if (ch[1] != "") {
                wchartInstance.series[n + num].setData(eval(tc2));
                num = num + 1;
            }
            if (ch[2] != "") {
                wchartInstance.series[n + num].setData(eval(tc3));
                num = num + 1;
            }
            if (ch[3] != "") {
                wchartInstance.series[n + num].setData(eval(tc4));
                num = num + 1;
            }

        });
    }
};

function search() {
    dtOpstart = $('#dtOpstart').datebox('getValue');
    dtOpend = $('#dtOpend').datebox('getValue');
    var ruleArr = [];
    if (cid != "") {
        ruleArr.push({ "field": "devID", "op": "eq", "data": cid });
    }
    if (dtOpstart != '')
        ruleArr.push({ "field": "updateTime", "op": "ge", "data": dtOpstart });
    if (dtOpend != '')
        ruleArr.push({ "field": "updateTime", "op": "le", "data": dtOpend });
    if (ruleArr.length > 0) {
        filterObj = { groupOp: 'AND', rules: ruleArr };
        $('body').data('where', JSON.stringify(filterObj));
        $('#histList').datagrid({
            queryParams: { filter: JSON.stringify(filterObj), devID: cid },
            url: actionURL + '?Action=detail'
        });
    } else {
        $('#histList').datagrid({
            queryParams: { devID: cid },
            url: actionURL + '?Action=detail'
        });
    }
}
$(function () {
    Highcharts.setOptions({
        lang: {
            contextButtonTitle: "图表导出菜单",
            decimalPoint: ".",
            downloadJPEG: "下载JPEG图片",
            downloadPDF: "下载PDF文件",
            downloadPNG: "下载PNG文件",
            downloadSVG: "下载SVG文件",
            drillUpText: "返回 {series.name}",
            loading: "加载中",
            months: ["一月", "二月", "三月", "四月", "五月", "六月", "七月", "八月", "九月", "十月", "十一月", "十二月"],
            noData: "没有数据",
            numericSymbols: ["千", "兆", "G", "T", "P", "E"],
            printChart: "打印图表",
            resetZoom: "恢复缩放",
            resetZoomTitle: "恢复图表",
            shortMonths: ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"],
            thousandsSep: ",",
            weekdays: ["星期一", "星期二", "星期三", "星期三", "星期四", "星期五", "星期六", "星期天"]
        }
    });

    //var size = { width: $(window).width(), height: $(window).height() };
    var size = { width: 990, height: 560 };
    $('#dtOpstart,#dtOpend').datebox({ width: 100 });
    mylayout.init(size);
    grid.bind(size);
    //uid = getUrlParam("devid");
    Minit();
    //autoResize({ dataGrid: '#histList', gridType: 'datagrid', callback: grid.bind, height: 0 });
    ChartJS.init(ch[0], ch[1], ch[2], ch[3]);
    $('#a_search').click(search);
    $('#a_weather').click(CRUD.show);
    $('#avgbtn').click(CRUD.showavg);
    $('#mavg').click(CRUD.showmavg);
    $('#avgbtnday').click(phoneavg);
    $('#avgbtnm').click(phoneavgm);
    $('#avgbtnx').click(phoneavgx);
    $(window).resize(function () {
        size = { width: $(window).width(), height: $(window).height() };
        mylayout.resize(size);
    });
    InitSendUser();
});